#include <osgDB/ReadFile>
#include <osgDB/WriteFile>
#include <FileNode.h>
FileNode::FileNode(const std::string &file_path) : osg::MatrixTransform()
{
    m_fileNode = osgDB::readNodeFile(file_path);
    m_fileName = file_path;
    this->addChild(m_fileNode);
}

FileNode::FileNode(const FileNode & file_node, const osg::CopyOp &copyop) : MatrixTransform(file_node,copyop)
{
    //FileNode* node_ptr = const_cast<FileNode*>(&file_node);
    //node_ptr->m_fileNode = node_ptr->getChild(0);

    m_fileNode = new osg::Node();
    this->m_fileNode = getChild(0);
    m_fileName = file_node.m_fileName;
}

FileNode::~FileNode()
{

}

void FileNode::changeFilePath(const std::string &file_path)
{
    this->removeChild(m_fileNode.get());
    m_fileNode = osgDB::readNodeFile(file_path);
    this->addChild(m_fileNode);
    m_fileName = file_path;
}

void FileNode::saveToFile(const std::string &fileName)
{
    osgDB::writeNodeFile( *(m_fileNode.get()), fileName);
    m_fileName = fileName;
}

std::string FileNode::getFileName()
{
    return m_fileName;
}

osg::Object *FileNode::cloneType() const
{
    return new FileNode("D:/Eric/Coding/3rd-party/osg/data/cow.osg");
}

osg::Object *FileNode::clone(const osg::CopyOp &copyop) const
{
    return new FileNode(*this, copyop);
}

//void FileNode::setFileName(const std::string &fileName)
//{
//    m_fileName = fileName;
//}
